<script>
function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>
<?php
$sql="SELECT substr( QUYEN,8, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 header('Location: index.php?page=id_edit_km&amp;id_edit_km="'.$_GET['id_edit_km'].'"'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
  <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ DANH MỤC KHUYẾN MÃI</th>
        </tr> 
        </thead>   
  <tr valign="top" style="padding:5px;">
    <td width="45%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
      <table width="87%" border="1" bordercolor="#666666" class="adminlist_tt">
        <thead>
          <tr>
            <th colspan="2">Sửa thông tin khuyến mãi</th>
          </tr>
	<?php  
if(isset($_POST['btn_edit_km'])){ 
	$makm=$_GET['id_edit_km'];
	$td=$_POST['txt_td_km'];
	$nd=$_POST['area_ndkm'];
	/////////////////////////////
	$sql1 = "update qldl_phuong_tien set				
				TIEU_DE='$td',
				NOI_DUNG='$nd'
			where MA_PHUONG_TIEN='$makm'
			";
	$query1 = @mysql_query($sql1,$conn);
	if($query1)echo "<script>alert ('Cập nhật thông tin thành công.')</script>";	
	else echo "<script>alert ('Lỗi cập nhật thông tin!')</script>";
		   
		   }
		   ?>

        </thead>
        <tbody>
        <form action="" method="post" name="form_edit" id="form_edit" onsubmit="return input_edit();">
<?php  
	$sql="select * from qldl_khuyen_mai where MA_KHUYEN_MAI='".$_GET['id_edit_km']."'";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else $row = @mysql_fetch_array($query);
		
  ?>
          <tr>
            <td width="115">Mã khuyến mãi</td>
            <td width="287">
              <label for="txt_ma_km"></label>
              <input type="text" name="txt_ma_km" id="txt_ma_km" value="<?php echo $row['MA_KHUYEN_MAI'];?>" readonly />
           	</td>
          </tr>
          
          <tr>
            <td height="12">Tiêu đề </td>
            <td>
              <label for="txt_td_km"></label>
              <input type="text" name="txt_td_km" id="txt_td_km" value="<?php echo $row['TIEU_DE'];?>" />
            </td>
          </tr>
          <tr>
            <td height="12">Nội dung</td>
            <td><textarea name="area_ndkm" id="area_ndkm" style="height:100px; width:100%;" value="<?php echo $row['NOI_DUNG'];?>"><?php echo $row['NOI_DUNG'];?></textarea></td>
          </tr>
                   
          <tr>
            <td colspan="2">
              <input type="submit" name="btn_edit_km" id="btn_edit_km" value="Lưu" onclick='window.location.href="index.php?page=km"' />
              <input type="reset" name="Reset" id="button" value="Hủy" onclick='window.location.href="index.php?page=km"'>
                      
            
            </td>
          </tr>
          </form>
        </tbody>
      </table>
    </div></td>
    <td width="60%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left" >
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt" >
              <thead>
                <tr>
                  <th colspan="4"> Danh mục khuyến mãi</th>
                
                </tr>
              </thead>
              <tbody>
                <form action="" method="post" name="form_view" id="form_view">
                <tr>
                  <td width="51">Stt</td>
                  <td width="67">Mã số</td>
                  <td width="236">Tiêu đề</td>
                  <td width="130">Cập nhật</td>
                </tr>
                <?php
				$stt=0;
	$sql="select * from qldl_khuyen_mai";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>	 
                <tr>
                  <td><?php echo $stt;?></td>
                  <td><?php echo $row['MA_KHUYEN_MAI'];?></td>
                  <td><?php echo $row['TIEU_DE'];?></td>
                  <td><a href="index.php?page=id_edit_km&amp;id_edit_km=<?php echo $row['MA_KHUYEN_MAI'];?>">Sửa</a> || 
                  <a onclick="Del_Info('index.php?page=km&amp;id_del_km=<?php echo $row['MA_KHUYEN_MAI']; ?>');" href="#">Xóa</a></td>
                </tr>
                <?php } ?>
                </form>
              </tbody>
            </table>
          </div></td>
  </tr>
</table>
   </div>
  </div>
</div>